package ntut.andengine.physics;

import java.util.ArrayList;
import java.util.List;

import ntut.andengine.game.GameLevel;
import ntut.andengine.physics.DeathLight.Direction;
import ntut.andengine.physics.PhysicalComponent.ComponentColor;

import com.badlogic.gdx.math.Vector2;

 public class PhysicalFactory {

	 static public Player CreateSparkle(GameLevel level, Vector2 position, ComponentColor color){
		 Player player = new Player(level);
         player.setPosition(position);
         player.changeColor(color);

         return player;
	 }
	 
	 static public List<PhysicalComponent> CreateWall(GameLevel level, Vector2 position, float width, float height, ComponentColor color)
     {
         List<PhysicalComponent> wallList = new ArrayList<PhysicalComponent>();

         for (int i = 0; i < width; i += 20)
         {
             for (int j = 0; j < height; j += 20)
             {
                 Wall wall = new Wall(level);
                 Vector2 offSet = new Vector2(position.x-width / 2 + i+10, position.y-height / 2 + j+10);
                 wall.setPosition(offSet);
                 wall.setColor(color);
                 wallList.add(wall);
                 level.addColorComponent(wall);
             }
         }

         return wallList;
     }
	 
	 static public Bar CreateBar(GameLevel level, Vector2 position, ComponentColor color, Vector2 velocity, boolean isVertical)
     {
         Bar bar = new Bar(level, isVertical);
         bar.setPosition(position);
         bar.setColor(color);
         bar.setVelocity(velocity);
         if (isVertical)
         {
             bar.getBody().setTransform(bar.getBody().getPosition(), (float)Math.PI / 2);
         }
         level.addColorComponent(bar);
         
         return bar;
     }
	 
	 static public PhysicalComponent CreateTransmissionGate(GameLevel level, Vector2 position)
     {
         TransmissionGate gate = new TransmissionGate(level);
         gate.setPosition(position);
         gate.setColor(ComponentColor.White);
         
         return gate;
     }
	 
	 static public PhysicalComponent CreateLaunchingPad(GameLevel level, Vector2 position, boolean isVertical)
     {
         LaunchingPad pad = new LaunchingPad(level);
         pad.setPosition(position);
         pad.setColor(ComponentColor.White);
         if (isVertical)
         {
             pad.getBody().setTransform(pad.getBody().getPosition(), (float)Math.PI / 2);
         }

         return pad;
     }
	 
	 static public List<DeathLight> CreateDeathLight(GameLevel level, Vector2 position, float width, float height, Direction direction)
     {
         List<DeathLight> deatLightList = new ArrayList<DeathLight>();

         for (int i = 0; i < width; i += 20)
         {
             for (int j = 0; j < height; j += 20)
             {
            	 DeathLight deathLight = new DeathLight(level, direction);     	 
            	 Vector2 newPosition = new Vector2(position.x-width / 2 + i + 10, position.y-height / 2 + j + 10);
                 deathLight.setPosition(newPosition);
                 deathLight.getParticleEmitter().setCenter(newPosition.x-20, newPosition.y-10);
                 deathLight.setColor(ComponentColor.White);
                 deatLightList.add(deathLight);
             }
         }

         return deatLightList;
     }
	 
	 static public SwitchDevice CreateSwitchDevice(GameLevel level, Vector2 position, boolean isVertical, List<DeathLight> deatLightList)
     {
         SwitchDevice switchDevice = new SwitchDevice(level, isVertical);
         switchDevice.setDeatLightList(deatLightList);
         switchDevice.setPosition(position);
         switchDevice.setColor(ComponentColor.White);
         if (isVertical)
         {
             switchDevice.getBody().setTransform(switchDevice.getBody().getPosition(), (float)Math.PI / 2);
         }

         return switchDevice;
     }
	 
	 static public BarSwitch CreateBarSwitch(GameLevel level, Vector2 position, boolean isVertical, List<Bar> barList)
     {
		 BarSwitch barSwitch = new BarSwitch(level, isVertical);
		 barSwitch.setBarList(barList);
		 barSwitch.setPosition(position);
		 barSwitch.setColor(ComponentColor.White);
         if (isVertical)
         {
        	 barSwitch.getBody().setTransform(barSwitch.getBody().getPosition(), (float)Math.PI / 2);
         }

         return barSwitch;
     }
	 
	 static public PhysicalComponent CreateBox(GameLevel level, Vector2 position, ComponentColor color)
     {
         Box box = new Box(level);
         box.setPosition(position);
         box.setColor(color);
         level.addColorComponent(box);
         
         return box;
     }
	 
	 static public Frame CreateFrame(GameLevel level, Vector2 position, ComponentColor color, int side){
		 
		 Frame frame = new Frame(level, side);
		 frame.setPosition(position);
		 frame.setColor(color);
		 
		 return frame;
	 }
}
